print("迭代对象##################################################start")
# Python的迭代不仅可以用在list或tuple上，还可以作用在其他可迭代对象，它的抽象层次更高
d = {"name": "wx", "age": 18, "add": "江西南昌"}

for key in d:  # 迭代map的key
    print(key)

for value in d.values():  # 迭代map的vuale
    print(value)

for k, v in d.items():  # 迭代map的key与vuale
    print(k, ":", v)

for str in "wx":  # 迭代字符串
    print(str)

# 验证对象是否可以迭代
from collections import Iterable

print(isinstance("wx1993", Iterable))
print(isinstance([1, 2, 3], Iterable))
print(isinstance(([1, 2, 3]), Iterable))
print(isinstance({"wx": "wx"}, Iterable))
print(isinstance(123456, Iterable))

# 实现下标遍历
array = [1, 2, 3, 4, 5]
for i, v in enumerate(array):  # enumerate函数可以把一个list变成索引-元素对
    print(i, ":", v)
array = [(2, 1), (2, 2), (2, 3), (2, 4), (2, 5)]
for i, v in array:
    print(i, ":", v)
print("迭代对象##################################################end\n")
